SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the UserAccount table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserAccount_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Username varchar (50)  = null ,

	@Title nvarchar (20)  = null ,

	@FirstName nvarchar (50)  = null ,

	@LastName nvarchar (50)  = null ,

	@Password nvarchar (50)  = null ,

	@PasswordSalt nvarchar (50)  = null ,

	@LastLogin datetime   = null ,

	@UserType int   = null ,

	@CreatedDate datetime   = null ,

	@UpdatedDate datetime   = null ,

	@CreatedUser varchar (50)  = null ,

	@UpdatedUser varchar (50)  = null ,

	@IsActivity bit   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Username]
	, [Title]
	, [FirstName]
	, [LastName]
	, [Password]
	, [PasswordSalt]
	, [LastLogin]
	, [UserType]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
	, [IsActivity]
    FROM
	[dbo].[UserAccount]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Username] = @Username OR @Username IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([FirstName] = @FirstName OR @FirstName IS NULL)
	AND ([LastName] = @LastName OR @LastName IS NULL)
	AND ([Password] = @Password OR @Password IS NULL)
	AND ([PasswordSalt] = @PasswordSalt OR @PasswordSalt IS NULL)
	AND ([LastLogin] = @LastLogin OR @LastLogin IS NULL)
	AND ([UserType] = @UserType OR @UserType IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([UpdatedDate] = @UpdatedDate OR @UpdatedDate IS NULL)
	AND ([CreatedUser] = @CreatedUser OR @CreatedUser IS NULL)
	AND ([UpdatedUser] = @UpdatedUser OR @UpdatedUser IS NULL)
	AND ([IsActivity] = @IsActivity OR @IsActivity IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Username]
	, [Title]
	, [FirstName]
	, [LastName]
	, [Password]
	, [PasswordSalt]
	, [LastLogin]
	, [UserType]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
	, [IsActivity]
    FROM
	[dbo].[UserAccount]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Username] = @Username AND @Username is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([FirstName] = @FirstName AND @FirstName is not null)
	OR ([LastName] = @LastName AND @LastName is not null)
	OR ([Password] = @Password AND @Password is not null)
	OR ([PasswordSalt] = @PasswordSalt AND @PasswordSalt is not null)
	OR ([LastLogin] = @LastLogin AND @LastLogin is not null)
	OR ([UserType] = @UserType AND @UserType is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([UpdatedDate] = @UpdatedDate AND @UpdatedDate is not null)
	OR ([CreatedUser] = @CreatedUser AND @CreatedUser is not null)
	OR ([UpdatedUser] = @UpdatedUser AND @UpdatedUser is not null)
	OR ([IsActivity] = @IsActivity AND @IsActivity is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
